<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<th:block th:include="include :: header('发射机设置')"/>
</head>
<style>
	.layui-form-label {
		width: 200px !important;
		text-align: left !important;
	}

	.layui-form-item .layui-input-inline {
		width: 200px !important;
		margin-bottom: 0px !important;
	}

	.layui-form-item-te {
		margin-bottom: 0px !important;
	}
</style>
<body class="pear-container">
<div class="layui-card">
	<form class="layui-form layui-form-pane" action="" id="tranform"  lay-filter="tranform">
		<div class="layui-form-item layui-form-item-te" style="padding-left: 10%;padding-top: 5%;">
			<label class="layui-form-label" style="width: 7%">台站ID</label>
			<div class="layui-input-inline" style="width: 12%">
				<select id="stationCode" name="stationCode" lay-verify="required"
						lay-filter="getTransmitter" >
				</select>
			</div>
			<label class="layui-form-label" style="width: 7%">台站IP</label>
			<div class="layui-input-inline" style="width: 12%">
				<input type="text" class="layui-input" id="stationIP" name="stationIP" autocomplete="off" >
			</div>
			<label class="layui-form-label" style="width: 7%">台站服务端口</label>
			<div class="layui-input-inline" style="width: 12%">
				<input type="text" class="layui-input" id="stationPort" name="stationPort" autocomplete="off" >
			</div>
		</div>
		<div class="layui-form-item layui-form-item-te" style="padding-left: 10%;padding-top: 1%;">
			<label class="layui-form-label" style="width: 7%">发射机ID</label>
			<div class="layui-input-inline" style="width: 12%">
				<select id="transCode" name="transCode" lay-verify="required"  >
				</select>
			</div>
			<label class="layui-form-label" style="width: 7%">发射机名称</label>
			<div class="layui-input-inline" style="width: 12%">
				<input type="text" class="layui-input" id="transName" name="transName" autocomplete="off" >
			</div>
			<label class="layui-form-label" style="width: 7%">最大功率</label>
			<div class="layui-input-inline" style="width: 12%">
				<input type="text" class="layui-input" id="power" name="power" autocomplete="off" >
			</div>
		</div>
		<div class="layui-form-item layui-form-item-te" style="padding-left: 10%;padding-top: 1%;">
				<label class="layui-form-label" style="width: 7%">地址</label>
				<div class="layui-input-inline" style="width: 12%">
					<input type="text" class="layui-input" id="address" name="address" autocomplete="off" >
				</div>
				<label class="layui-form-label" style="width: 7%">经度</label>
				<div class="layui-input-inline" style="width: 12%">
					<input type="text" class="layui-input" id="longitude" name="longitude" autocomplete="off" >
				</div>
				<label class="layui-form-label" style="width: 7%">纬度</label>
				<div class="layui-input-inline" style="width: 12%">
					<input type="text" class="layui-input" id="latitude" name="latitude" autocomplete="off" >
				</div>
		</div>
		<div class="layui-form-item layui-form-item-te" style="padding-left: 10%;padding-top: 1%;">
			<label class="layui-form-label" style="width: 7%">发射机ip</label>
			<div class="layui-input-inline" style="width: 12%">
				<input type="text" class="layui-input" id="transIp1" name="transIp1" autocomplete="off" >
			</div>
			<label class="layui-form-label" style="width: 7%">发射机http_port</label>
			<div class="layui-input-inline" style="width: 12%">
				<input type="text" class="layui-input" id="transHttpPort" name="transHttpPort" autocomplete="off" >
			</div>
			<label class="layui-form-label" style="width: 7%">发射机https_port</label>
			<div class="layui-input-inline" style="width: 12%">
				<input type="text" class="layui-input" id="transHttpsPort" name="transHttpsPort" autocomplete="off" >
			</div>
		</div>
		<div class="layui-form-item layui-form-item-te" style="padding-left: 10%;padding-top: 1%;">
			<label class="layui-form-label" style="width: 7%">发射机天线程式</label>
			<div class="layui-input-inline" style="width: 12%">
				<input type="text" class="layui-input" id="antennaProgram" name="antennaProgram" autocomplete="off" >
			</div>
			<label class="layui-form-label" style="width: 7%">运行状态数据上报时间间隔</label>
			<div class="layui-input-inline" style="width: 12%">
				<input type="text" class="layui-input" id="statusPeriod" name="statusPeriod" autocomplete="off" >
			</div>
			<label class="layui-form-label" style="width: 7%">单任务默认播音时长</label>
			<div class="layui-input-inline" style="width: 12%">
				<input type="text" class="layui-input" id="oneTaskPlayTime" name="oneTaskPlayTime" autocomplete="off" >
			</div>
		</div>
		<div class="layui-form-item layui-form-item-te" style="padding-left: 10%;padding-top: 1%;">
			<label class="layui-form-label" style="width: 7%">是否支持跳频</label>
			<div class="layui-input-inline" style="width: 12%">
				<select id="isHopped" name="isHopped" lay-verify="required"  >
					<option value="1">是</option>
					<option value="2">否</option>
				</select>
			</div>
			<label class="layui-form-label" style="width: 7%">操作类型</label>
			<div class="layui-input-inline" style="width: 12%">
				<select id="operType" name="operType" lay-verify="required"  >
					<option value="1">新增</option>
					<option value="2">替换/修改</option>
				</select>
			</div>
			<label class="layui-form-label" style="width: 7%">发射机重启</label>
			<div class="layui-input-inline" style="width: 12%">
				<select id="transReset" name="transReset" lay-verify="required"  >
					<option value="0">上电服务</option>
					<option value="1">服务器重启</option>
					<option value="2">其他</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item layui-form-item-te" style="padding-left: 10%;padding-top: 1%;">
			<label class="layui-form-label" style="width: 7%">天线</label>
			<div class="layui-input-inline" style="width: 12%">
				<input type="text" class="layui-input" id="antenna" name="antenna" autocomplete="off" >
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block" style="text-align: center; margin-right:10%;padding-top: 5%;">
				<button class="layui-btn" th:type="button" lay-filter="transmiterSet" onclick="transmiterSet()">
					添加
				</button>
				<button class="layui-btn" th:type="button" lay-filter="closeTransmiter" onclick="closeTransmiter()">
					关闭
				</button>
			</div>
		</div>
	</form>
</div>
</body>
<th:block th:include="include :: footer"/>
<script>
	layui.use(['table', 'form', 'popup', 'jquery', 'element', 'util','layer','select'], function () {
		let form = layui.form;
		let popup = layui.popup;
		let MODULE_PATH = "/system/transmitter/";
		/**
		 * 终端系统信息设置模板(后续去除系统信息无需设置)
		 */
		form.on('select(getTransmitter)', function (data) {
			getTransmitter(data.value);
		});
		window.transmiterSet = function () {
			var d = {};
			var t = $('#tranform').serializeArray();
			$.each(t, function() {
				d[this.name] = this.value;
			});
			$.ajax({
				url: MODULE_PATH + 'addTransmitter',
				type: 'POST',
				contentType: 'application/json;charset=UTF-8',
				data: JSON.stringify(d),
				success: function (data) {
					if (data.code === 200) {
						popup.success(data.msg);
						window.parent.location.reload();
						varindex = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
					} else {
						popup.failure(data.msg);
					}
				},
				error: function () {
					popup.failure("添加发射机接口访问失败!")
				}
			});
		}
		window.closeTransmiter = function () {
			window.parent.location.reload();
			varindex = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		}
		$.ajax({
			url:  '/system/transmitter/getStations',
			type: 'get',
			contentType: 'application/json;charset=UTF-8',
			success: function (data) {
				$("#stationCode").empty();
				if (data.code == 0) {
					$.each(data.data, function (index, item) {
						$("#stationCode").append(new Option( item.title, item.id));// 下拉菜单里添加元素
					});
					layui.form.render("select");
					if(data.data.length>0){
						getTransmitter(data.data[0].id);
					}
				} else {
					popup.failure(data.msg);
				}
			},
			error: function () {
				popup.failure("获取台站接口访问失败!")
			}
		});
		function getTransmitter(stationCode){
			$.ajax({
				url:  "/system/transmitter/getTransmitter?stationCode=" + stationCode,
				type: 'get',
				contentType: 'application/json;charset=UTF-8',
				success: function (data) {
					$("#transCode").empty();
					if (data.code == 200) {
						$.each(data.data, function (index, item) {
							$("#transCode").append(new Option( item.transName, item.id));// 下拉菜单里添加元素
						});
						layui.form.render("select");
					} else {
						popup.failure(data.msg);
					}
				},
				error: function () {
					popup.failure("获取发射机接口访问失败!")
				}
			});
		}
	})
</script>
</html>